package exp;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimerTask;

public class ITimeTask extends TimerTask {

    private Integer count = 0;

    private String name;

    public ITimeTask(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        if (count > 3) {
            cancel();
            System.out.println("task cancel");
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            long l = scheduledExecutionTime();
            System.out.println(" " + name + sdf.format(l));
            Calendar calendar = Calendar.getInstance();

            System.out.println(sdf.format(calendar.getTime()));
            count++;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
